package goodbaby.dklt.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.squareup.picasso.Picasso;

import java.util.List;

import goodbaby.dklt.R;
import goodbaby.dklt.bean.LeaveBean;

/**
 * Created by Jayden on 2016/
 *
 * @version V1.0
 * @Title: LeaveHistoryAdapter
 * @Description: 请假历史适配器
 */
public class LeaveHistoryAdapter extends BaseAdapter {
    private Context context;
    private List<LeaveBean> data;

    public LeaveHistoryAdapter(Context paramContext, List<LeaveBean> paramList) {
        this.context = paramContext;
        this.data = paramList;
    }

    public int getCount() {
        return data.size();
    }

    public Object getItem(int paramInt) {
        return data.get(paramInt);
    }

    public long getItemId(int paramInt) {
        return paramInt;
    }

    public View getView(int paramInt, View paramView, ViewGroup paramViewGroup) {
        ViewHolder localViewHolder;
        if (paramView == null) {
            paramView = LayoutInflater.from(context).inflate(R.layout.item_leave_history, null);
            localViewHolder = new ViewHolder();
            localViewHolder.tvDate = ((TextView) paramView.findViewById(R.id.item_tv_date));
            localViewHolder.tvReason = ((TextView) paramView.findViewById(R.id.item_tv_reason));
            localViewHolder.tvTime = ((TextView) paramView.findViewById(R.id.item_tv_time));
            localViewHolder.tvName = ((TextView) paramView.findViewById(R.id.item_tv_name));
            localViewHolder.tvConfirmTime = ((TextView) paramView.findViewById(R.id.item_tv_confirm_time));
            localViewHolder.ivStatus = ((ImageView) paramView.findViewById(R.id.iv_leave_status));
            localViewHolder.llApprover = ((LinearLayout) paramView.findViewById(R.id.ll_approver));
            paramView.setTag(localViewHolder);
        } else {
            localViewHolder = (ViewHolder) paramView.getTag();
        }
        localViewHolder.tvDate.setText(data.get(paramInt).getCreatedOn());
        localViewHolder.tvReason.setText("请假事由:" + data.get(paramInt).getReason());
        localViewHolder.tvTime.setText("休假时间:" + data.get(paramInt).getBeginDate() + "-" + data.get(paramInt).getEndDate());
        localViewHolder.tvName.setText("批复人:" + data.get(paramInt).getTeacherName());
        localViewHolder.tvConfirmTime.setText("批复时间:" + data.get(paramInt).getApproverDate());
        if (data.get(paramInt).getSTATUS() == 0) {
            Picasso.with(context).load(R.mipmap.leave_status_wait).into(localViewHolder.ivStatus);
            localViewHolder.llApprover.setVisibility(View.GONE);
        } else if (data.get(paramInt).getSTATUS() == 1) {
            Picasso.with(context).load(R.mipmap.leave_status_true).into(localViewHolder.ivStatus);
            localViewHolder.llApprover.setVisibility(View.VISIBLE);
        } else {
            Picasso.with(context).load(R.mipmap.leave_status_false).into(localViewHolder.ivStatus);
            localViewHolder.llApprover.setVisibility(View.VISIBLE);
        }
        return paramView;
    }

    class ViewHolder {
        ImageView ivStatus;
        LinearLayout llApprover;
        TextView tvConfirmTime;
        TextView tvDate;
        TextView tvName;
        TextView tvReason;
        TextView tvTime;
    }
}
